<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<script type="text/javascript">
    var appGoodsManageDataGrid;
    $(function() {
        appGoodsManageDataGrid = $('#appGoodsManageDataGrid').datagrid({
            url : '${path }/appGoodsManage/dataGrid',
            striped : true,
            rownumbers : true,
            pagination : true,
            singleSelect : true,
            idField : 'id',
            sortName : 'id',
            sortOrder : 'asc',
            pageSize : 20,
            pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400, 500 ],
            frozenColumns : [ [ {
                title : 'id',
                field : 'id',
                width : 40,
                hidden : true
            } ] ],
            columns : [ [ {
                field : 'goodsCode',
                title : '编码',
                width : 60
            },{
                field : 'goodsName',
                title : '商品名称 ',
                width : 180
            },{
                field : 'goodsWeight',
                title : '重量 ',
                width : 70
            },{
                field : 'goodsSpec',
                title : '规格 ',
                width : 70
            },{
                field : 'goodsPrice',
                title : '价格',
                width : 70
            },{
                field : 'amount',
                title : '库存',
                width : 120
            },{
                field: 'goodsStatus',
                title: '上下架',
                width: '80',
                sortable:true,
                formatter : function(value, row, index){
                    switch (value){
                        case 1:
                            return '上架';
                        case 0:
                            return '下架';
                    }
                }
            },{
                width : '80',
                title : '停售',
                field : 'goodsStopFlag',
                sortable : true,
                formatter : function(value, row, index) {
                    switch (value) {
                        case 0:
                            return '启用';
                        case 1:
                            return '停用';
                    }
                }
            }, {
                width : '150',
                title : '创建时间',
                field : 'createTime'
            },{
                field : 'action',
                title : '操作',
                width : 135,
                formatter : function(value, row, index) {
                    var str = '';
                    <shiro:hasPermission name="/appGoodsManage/edit">
                      str += $.formatString('<a href="javascript:void(0)" class="appGoodsManage-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="editAppGoodsManageFun(\'{0}\');" >编辑</a>', row.id);
                    </shiro:hasPermission>
                    <shiro:hasPermission name="/appGoodsManage/delete">
                       str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                       str += $.formatString('<a href="javascript:void(0)" class="appGoodsManage-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="deleteAppGoodsManageFun(\'{0}\');" >删除</a>', row.id);
                    </shiro:hasPermission>
                    return str;
                }
            } ] ],
            onLoadSuccess:function(data){
                $('.appGoodsManage-easyui-linkbutton-del').linkbutton({text:'删除'});
                $('.appGoodsManage-easyui-linkbutton-edit').linkbutton({text:'编辑'});
            },
            toolbar : '#appGoodsManageToolbar'
        });
    });

    function addAppGoodsManageFun() {
        parent.$.modalDialog({
            title : '添加',
            width : 500,
            height : 300,
            href : '${path }/appGoodsManage/addPage',
            buttons : [ {
                text : '确定',
                handler : function() {
                    parent.$.modalDialog.openner_dataGrid = appGoodsManageDataGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#appGoodsManageAddForm');
                    f.submit();
                }
            } ]
        });
    }

    function editAppGoodsManageFun(id) {
        if (id == undefined) {
            var rows = appGoodsManageDataGrid.datagrid('getSelections');
            id = rows[0].id;
        } else {
            appGoodsManageDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.modalDialog({
            title : '编辑',
            width : 500,
            height : 300,
            href : '${path }/appGoodsManage/editPage?id=' + id,
            buttons : [ {
                text : '确定',
                handler : function() {
                    parent.$.modalDialog.openner_dataGrid = appGoodsManageDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#appGoodsManageEditForm');
                    f.submit();
                }
            } ]
        });
    }

    function deleteAppGoodsManageFun(id) {
        if (id == undefined) {//点击右键菜单才会触发这个
            var rows = appGoodsManageDataGrid.datagrid('getSelections');
            id = rows[0].id;
        } else {//点击操作里面的删除图标会触发这个
            appGoodsManageDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.messager.confirm('询问', '您是否要删除？', function(b) {
            if (b) {
                progressLoad();
                $.post('${path }/appGoodsManage/delete', {
                    id : id
                }, function(result) {
                    if (result.success) {
                        parent.$.messager.alert('提示', result.msg, 'info');
                        appGoodsManageDataGrid.datagrid('reload');
                    }
                    progressClose();
                }, 'JSON');
            }
        });
    }


</script>
<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'center',fit:true,border:false">
        <table id="appGoodsManageDataGrid" data-options="fit:true,border:false"></table>
    </div>
</div>
<div id="appGoodsManageToolbar" style="display: none;">
    <shiro:hasPermission name="/appGoodsManage/add">
        <a onclick="addAppGoodsManageFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-plus icon-green'">添加</a>
    </shiro:hasPermission>
</div>